﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="OrderAdd.aspx.cs" Inherits="CNVP.JShop.Web.Member.OrderAdd" %>
<%@ Register src="Footer.ascx" tagname="Footer" tagprefix="uc1" %>
<%@ Register src="Header.ascx" tagname="Header" tagprefix="uc1" %>
<%@ Register src="LeftNav.ascx" tagname="LeftNav" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>添加订单</title>
    <link href="css/Global.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/Fonts.css" rel="stylesheet" type="text/css" media="all"  />
<link href="css/Style.css" rel="stylesheet" type="text/css" media="all" />
<link href="../CSS/MemberCenter.css" rel="stylesheet" type="text/css" media="all" />
    <script src="../Scripts/jquery.js" type="text/javascript"></script>
<script type="text/javascript" src="js/procp.js"></script>
    <script src="../Scripts/Common.js" type="text/javascript"></script>
</head>
<body onload="OnLoadGetAddress();DeliveryFreight();DeliveryWayCheck();">
    <form id="form2" runat="server" autocomplete="off">
<uc1:Header ID="Header1" runat="server" />

<div class="Width MBody clearfix">
<uc1:LeftNav ID="LeftNav1" runat="server" />

<div class="MRight">
                <div class="MRightTitle"><p>添加订单</p></div>
                <div class="MRightBox">
      <div class="division">
                    <div id="ShopMustInfo" runat="server"></div>
                </div>
                <div class="division" id="GetTrueInfo">
                    <h3>收货信息确认</h3>
                    <asp:Repeater ID="rpList" runat="server">
                        <ItemTemplate>
                           <p>
                               <input id="rbIsTolerantA<%# Eval("ID")%>" type="radio" name="rbIsTolerant" <%# Eval("IsTolerant").ToString()=="1"? "checked='checked'":"" %> value="<%# Eval("ID")%>" onclick="IsTolerant1(<%# Eval("ID")%>)"  /> 
                               <%# new CNVP.JShop.BLL.CNVP_Province().GetSingle_CNVP_ProvinceByCode(Eval("Province").ToString()).Name %>
                               -
                               <%# new CNVP.JShop.BLL.CNVP_City().GetSingle_CNVP_CityByCode(Eval("City").ToString()).Name %>
                               -
                               <%# new CNVP.JShop.BLL.CNVP_Area().GetSingle_CNVP_AreaByCode(Eval("Area").ToString()).Name %>
                               <%# Eval("GetAddress") %>
                               (收货人：<%# Eval("TrueName")%> 手机：<%# Eval("MobilePhone")%> 邮编：<%# Eval("ZipCode")%> )
                               <input id="btGetAddressEdit<%# Eval("ID")%>" class="txtAmount" type="button" value="编辑" onclick="GetAddressEdit(<%# Eval("ID")%>);" />
                               </p>
                        </ItemTemplate>
                        <FooterTemplate><p id="idIsTolerant2"><input id="rbIsTolerant2" type="radio" name="rbIsTolerant" onclick="IsTolerant2()" /> 其他</p></FooterTemplate>
                    </asp:Repeater>

                    <script type="text/javascript">
                        function DeliveryFreight()
                        {
                            var getNumArray = "";
                            var Num = document.getElementsByName("Num");
                            for (var i = 0; i < Num.length; i++) {
                                getNumArray += Num[i].value + ",";
                            }
                            getNumArray = getNumArray.substring(0, getNumArray.length - 1);
                            var result=GetAjaxResponse("../Controls/DeliveryFreight.aspx?SaleNumArray="+getNumArray+"&ProductIDS=<%=ProductIDS %>&ListProvince="+$("#ListProvince").val()+"");
                            if(result!=null)
                            {
                                $("#DeliveryFreight").html(result);
                            }
                            DeliveryWayCheck();
                        }
                        function ProductsOnchang(proId, proDetailId)
                        {
                            var Allprice = 0.00;
                            var Num = document.getElementById("Num" + proId + "_" + proDetailId + "").value;
                            var NumCompare = document.getElementById("NumCompare" + proId + "_" + proDetailId + "").value;
                            var Price = document.getElementById("Price" + proId + "_" + proDetailId + "").innerHTML;
                            var spantotalPrice = document.getElementById("spantotalPrice" + proId + "_" + proDetailId + "");
                            var totalPrice = document.getElementById("totalPrice" + proId + "_" + proDetailId + "");
                            if (Num > 0) {
                                var NumState = GetAjaxResponse("../Controls/AjaxProDetailNum.aspx?OperType=Update&ProID=" + proId + "&ProDetailID=" + proDetailId + "&CompareValue=" + Num);
                                 if (NumState == "0") {
                                     alert("库存不足！");
                                     document.getElementById("Num" + proId + "_" + proDetailId + "").value = document.getElementById("NumCompare" + proId + "_" + proDetailId + "").value;
                                     Allprice = parseInt(NumCompare) * parseFloat(Price);
                                     spantotalPrice.innerHTML = Math.round(Allprice * 100) / 100;
                                     totalPrice.value = Math.round(Allprice * 100) / 100;
                                 }
                                 else {
                                     Allprice = parseInt(Num) * parseFloat(Price);
                                     spantotalPrice.innerHTML = Math.round(Allprice * 100) / 100;
                                     totalPrice.value = Math.round(Allprice * 100) / 100;
                                 }
                            }
                            else {
                                alert("请输入0的整数！");
                                document.getElementById("Num" + proId + "_" + proDetailId + "").value = document.getElementById("NumCompare" + proId + "_" + proDetailId + "").value;
                                Allprice = parseInt(NumCompare) * parseFloat(Price);
                                spantotalPrice.innerHTML = Math.round(Allprice * 100) / 100;
                                totalPrice.value = Math.round(Allprice * 100) / 100;
                            }
                            $("#FontSaleNum"+proId+"_"+proDetailId+"").html("x "+$("#Num"+proId+"_"+proDetailId+"").val());
                            DeliveryFreight();
                        }
                        function DeliveryWayCheck() {
                            var spanSalePriceTatol = document.getElementById("spanSalePriceTatol");
                            var inputSalePriceTatol = document.getElementById("inputSalePriceTatol");
                            var spanOrderTatol = document.getElementById("spanOrderTatol");
                            var inputOrderTatol = document.getElementById("inputOrderTatol");
                            var spanDeliveryPrice = document.getElementById("spanDeliveryPrice");
                            var inputDeliveryPrice = document.getElementById("inputDeliveryPrice");

                            var DeliveryWayPrice=0;
                            var rbDeliveryWayNum = document.getElementById("DeliveryWayPrice"); //配送价
                            if(rbDeliveryWayNum!=null)
                            {
                                var WayNum=rbDeliveryWayNum.value;
                                if(WayNum!="")
                                {
                                    var arrWayPrice=WayNum.split(":");
                                    DeliveryWayPrice=arrWayPrice[1];
                                }
                            }
                            var SalePriceTatol=0.00;
                            var OrderTatol = 0.00;
                            var getTotalList = 0.00;
                            var getTotalPrice = document.getElementsByName("totalPrice");
                             for (var i = 0; i < getTotalPrice.length; i++) {
                                getTotalList += parseFloat(getTotalPrice[i].value);
                             }
                             SalePriceTatol=Math.round(getTotalList * 100) / 100;
                             if (spanSalePriceTatol != null && inputSalePriceTatol!=null) {
                                 spanSalePriceTatol.innerHTML = SalePriceTatol;
                                 inputSalePriceTatol.value = SalePriceTatol;
                            }
                            OrderTatol = SalePriceTatol + parseFloat(DeliveryWayPrice);
                            if (spanDeliveryPrice != null && inputDeliveryPrice!=null) {
                                spanDeliveryPrice.innerHTML = DeliveryWayPrice;
                                inputDeliveryPrice.value = DeliveryWayPrice;
                            }
                            if (spanOrderTatol != null && inputOrderTatol != null) {
                                spanOrderTatol.innerHTML = OrderTatol;
                                inputOrderTatol.value = OrderTatol;
                           }
                        }
                        function OnLoadGetAddress() {
                            $("#GetAddressList").css("display", "none"); //先隐藏
                            if(<%=GetAddress_Int %> >0)
                            {
                                var rbIsTolerant = document.getElementsByName("rbIsTolerant");
                                for (var i = 0; i < rbIsTolerant.length; i++) {
                                    //alert(rbIsTolerant[i].value);
                                    if (rbIsTolerant[i].checked == true) {
                                        $("#GetAddressList").append(GetAjaxResponse("../Controls/GetAddress.aspx?ID=" + rbIsTolerant[i].value));
                                        ProvinceChange();
                                    }
                                }
                            }
                            else
                            {
                                $("#idIsTolerant2").addClass("Display");
                                IsTolerant2();
                            }
                            
                        }
                        function GetAddressEdit(index) {
                            $("#GetAddressList").css("display", "");
                            $("#rbIsTolerantA" + index + "").attr("checked", "checked");
                                var GetAddressList=document.getElementById("GetAddressList");
                                GetAddressList.innerHTML = "";
                                $("#GetAddressList").append(GetAjaxResponse("../Controls/GetAddress.aspx?ID=" + index));
                                ProvinceChange();
                               
                                //产生需要编辑ID
                                var EditChecked=document.getElementById("EditChecked");
                                EditChecked.innerHTML = "";
                                $("#EditChecked").append("<input id='EditGetAddressID' type='hidden' name='EditGetAddressID' value='" + index + "'>");
                                DeliveryFreight();
                        }
                        function IsTolerant1(index) {
                            $("#GetAddressList").css("display", "none");
                                var GetAddressList=document.getElementById("GetAddressList");
                                GetAddressList.innerHTML = "";
                                $("#GetAddressList").append(GetAjaxResponse("../Controls/GetAddress.aspx?ID=" + index));
                                ProvinceChange();
                                DeliveryFreight();
                        }
                        function IsTolerant2() {
                            $("#GetAddressList").css("display", "");
                             var GetAddressList=document.getElementById("GetAddressList");
                            GetAddressList.innerHTML = "";
                            $("#GetAddressList").append(GetAjaxResponse("../Controls/GetAddress.aspx"));
                            var EditChecked=document.getElementById("EditChecked");
                            EditChecked.innerHTML = "";
                            DeliveryFreight();
                        }
                    </script>
                    <div id="GetAddressList"></div><b id="EditChecked"></b>
                    <h3>配送价格</h3>
                    <span id="DeliveryFreight"></span>
                    <h3>支付方式确认</h3>
                    <asp:Label ID="lbPayWay" runat="server"></asp:Label>
                    <asp:Label ID="lbProductList" runat="server"></asp:Label>
                    <!--订单确认-->
                    <div id="OrderCheck" runat="server"></div>
                    <h3>是否需要发票</h3>
                    <input name="GetInvoice" value="1" type="checkbox" />需要
                    <h3>补充说明</h3>
                    <asp:TextBox ID="txtText" runat="server" TextMode="MultiLine" CssClass="OrderText"  OnClick="clickText('#txtText')" OnBlur="blurText('#txtText')"></asp:TextBox>
                </div>
                <br />
                <asp:Button ID="btUp" runat="server" Text="提交" OnClick="btUp_Click" />
                <input type="button" id="btnReturn" value="取消" onclick="javascript:history.go(-1)" />
                </div>
</div>
</div>

   
    <uc1:Footer ID="Footer1" runat="server" />
        </form>
<script type="text/javascript">
    jQuery(document).ready(CheckUserLogin); 
            $(function () {
            $("#btUp").click(function () {
                if(<%=GetAddress_Int %> >0)
                {
                    var $rbIsTolerant = $("input[name='rbIsTolerant'][type='radio']:checked");
                    if ($rbIsTolerant.length == 0) {
                        alert("请选择收货信息！");
                        $rbIsTolerant.focus();
                        return false;
                    }
                }
                var $ListProvince = $("#ListProvince");
                if ($ListProvince.val() == "") {
                    alert("请选择省区！");
                    $ListProvince.focus();
                    return false;
                }
                var $ListCity = $("#ListCity");
                if ($ListCity.val() == "") {
                    alert("请选择市区！");
                    $ListCity.focus();
                    return false;
                }
                var $ListArea = $("#ListArea");
                if ($ListArea.val() == "") {
                    alert("请选择地区！");
                    $ListArea.focus();
                    return false;
                }
                var $txtGetAddress = $("#txtGetAddress");
                if ($txtGetAddress.val() == "") {
                    alert("请输入收货地址！");
                    $txtGetAddress.focus();
                    return false;
                }
                var $txtZipCode = $("#txtZipCode");
                if($txtZipCode.val()!="")
                {
                    if(!IsPostId($txtZipCode.val()))
                    {
                        alert("邮编格式不正确！");
                        $txtZipCode.focus();
                        return false;
                    }
                }
                var $txtTrueName = $("#txtTrueName");
                if ($txtTrueName.val() == "") {
                    alert("请输入收货人姓名！");
                    $txtTrueName.focus();
                    return false;
                }
                var $txtMobilePhone = $("#txtMobilePhone");
                if ($txtMobilePhone.val() == "") {
                    alert("请输入手机号码！");
                    $txtMobilePhone.focus();
                    return false;
                }
                if(!IsValidMobilePhone($txtMobilePhone.val()))
                {
                    alert("手机号码格式不正确！");
                    $txtMobilePhone.focus();
                    return false;
                }
                var $txtPhone = $("#txtPhone");
                if($txtPhone.val()!="")
                {
                    if(!IsValidPhone($txtPhone.val()))
                    {
                        alert("电话号码格式不正确！");
                        $txtPhone.focus();
                        return false;
                    }
                }
                var $PayWay = $("input[name='PayWay'][type='radio']:checked");
                if ($PayWay.length == 0) {
                    alert("请选择支付方式！");
                    return false;
                }
                return true;
            });
        })     
</script>
</body>
</html>
